package cn.yuhh.core.domain;

import cn.yuhh.core.type.DeclareStatus;
import cn.yuhh.core.type.Whether;
import com.magic.spring.mongo.Mongo;
import lombok.Data;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-17 15:27
 * @descreption 申报信息
 **/
@Data
@Document(collection = "declare_info")
public class DeclareInfo extends Domain{

    private String placeName;       //场所名称

    private String addr;        //场所地址

    @Indexed
    private DeclareStatus declareStatus = DeclareStatus.accepted;

    private String  buildingId;      //场所所在建筑

    private String  buildingName;      //场所所在建筑

    private String area;            //场所面积

    @Indexed
    private AreaInfo areaInfo;

    private String usageType;           //使用性质

    private String header;          //负责人

    private String headerTel;          //负责人

    private String contacts;            //联系人

    private String contactsTel;

    private String placeDesc;       //场所简介

    private List<String> businessLicense; //营业执照(图片)

    private List<String> plan;            //场所平面图

    private List<String> photos;          //场所照片

    private String userId;              //申报人

    private String userName;              //申报人

    private String mainManagerId;        //主办人,

    private String otherManagerId;       //协办人

    private String reason; //原因


    public Map list(Map map){
        map.put("placeName", placeName);
        map.put("addr", addr);
        map.put("declareStatus", declareStatus);
        map.put("declareStatusName", declareStatus.getName());

        map.put("area", area);
        map.put("areaInfo", new HashMap(){{
            put("countyCode", areaInfo.getCountyCode());
            put("county", areaInfo.getCounty());
        }});
        map.put("buildingId", buildingId);
        map.put("buildingName", buildingName);
        map.put("usageType", usageType);
        map.put("contacts", contacts);
        map.put("contactsTel", contactsTel);
        map.put("id", getId());
        map.put("createString", getCreateTimeString());
        map.put("updateString", getUpdateTimeString());
        map.put("userId", userId);
        map.put("userName", userName);

        if(declareStatus.equals(DeclareStatus.unaccepted) || declareStatus.equals(DeclareStatus.callBack)){
            map.put("needHandle", Whether.O);
            map.put("menu", declareStatus.getMenu());
        }else if(this.declareStatus.equals(DeclareStatus.end)){
            map.put("needHandle", Whether.N);
        }else if(!StringUtils.isEmpty(this.mainManagerId) && this.mainManagerId.equals(map.get("selfId"))){
            map.put("needHandle", Whether.Y);
            map.put("menu", declareStatus.getMenu());
        }else if (!StringUtils.isEmpty(this.otherManagerId) && this.otherManagerId.equals(map.get("selfId"))){
            map.put("needHandle", Whether.Y);
            map.put("menu", declareStatus.getMenu());
        }else {
            //应该是N 没找到问题
            map.put("needHandle", Whether.N);
        }
        return map;
    }

    public Map detail(Map map){
        list(map);
        map.put("reason", reason);
        map.put("placeDesc", placeDesc);
        map.put("businessLicense", businessLicense);
        map.put("plan", plan);
        map.put("photos", photos);
        Building building = Mongo.buildMongo().eq("_id", buildingId).findOne(Building.class);
        map.put("storey", building.getStorey());
        map.put("height", building.getHeight());
        map.put("management", building.getManagement());
        map.put("mainManagerId",mainManagerId);
        User manager = Mongo.buildMongo().eq("_id", mainManagerId).findOne(User.class);
        if(manager != null){
            map.put("mainManagerName",manager.getName());
        }
        map.put("header", header);
        map.put("headerTel", headerTel);
        map.put("createAt", getCreateAt());
        map.put("updateAt", getUpdateAt());
        map.put("nextService", declareStatus.getNextService());
        if(declareStatus.equals(DeclareStatus.distExamine)){
            map.put("result", "合格");
        }
        if(declareStatus.equals(DeclareStatus.unqualified)){
            map.put("result", "不合格");
        }
        return map;
    }

}